﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;

public class ParticleQuality:MonoBehaviour
{
    char lv = '3';
    private void OnEnable()
    {
        char v = (char)(DevicePerformanceUtil.qualityLevel + 48);
        if (lv != v)
        {
            lv = v;
            var trans = transform;
            int c = trans.childCount;
            for (int i = 0; i < c; i++)
                SetLevel(trans.GetChild(i), lv);
        }
    }
    void SetLevel(Transform trans, char level)
    {
        string n = trans.name;
        if (n.Contains("_lv"))
        {
            char lv = n[n.Length - 1];
            bool state = lv <= level;
            var r = trans.GetComponent<Renderer>();
            if (r != null)
            {
                r.enabled = state;
            }
            else
            {
                var ps = transform.GetComponent<ParticleSystem>();
                if (ps != null)
                {
                    ps.shape.meshRenderer.enabled = state;
                }
            }
        }
        int c = trans.childCount;
        for (int i = 0; i < c; i++)
            SetLevel(trans.GetChild(i), level);
    }
}
